package com.cskaoyan.exception;

import com.cskaoyan.bean.BaseRespVo;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

/**
 * 异常处理
 * @author stone
 * @date 2022/01/03 11:27
 */
//@ControllerAdvice
//@ResponseBody
@RestControllerAdvice
public class ExceptionControllerAdvice {

    //@ExceptionHandler(value = {ArithmeticException.class})
    /*@ExceptionHandler(ArithmeticException.class)
    public ModelAndView arithmetic() {
        ModelAndView modelAndView = new ModelAndView("/arithmetic.jsp");
        return modelAndView;
    }*/

    /*@ExceptionHandler(ArithmeticException.class)
    public String arithmetic(){
        return "/arithmetic.jsp";//viewName
    }*/

    @ExceptionHandler(ArithmeticException.class)
    //@ResponseBody
    public BaseRespVo arithmetic(ArithmeticException exception) {
        //return BaseRespVo.fail("算术异常3.0");
        return BaseRespVo.fail(exception.getMessage());//by zero
    }
}
